
// 当前时间的一天后
export function getNextDay(){
	const today = new Date();
	today.setDate(today.getDate() + 1);
	return today;
	// const nextDay = getNextDay();
	// console.log(nextDay); // 输出当前日期的下一天的日期
}

// 返回当前时间的n小时后
export function getCurTimePlus(num) {  
	// 获取当前时间  
	let now = new Date();  
	// 获取当前小时  
	let hours = now.getHours();  
	// 如果加上2小时超过24小时，则进行小时数的调整  
	hours = (hours + num) % 24;  
	// 获取当前分钟  
	let minutes = now.getMinutes();  
	// 如果分钟数小于10，前面补0  
	minutes = minutes < 10 ? '0' + minutes : minutes;  
	// 格式化小时，如果小时数小于10，前面补0  
	hours = hours < 10 ? '0' + hours : hours;  
	// 拼接时间字符串  
	let newTime = hours + ':' + minutes;  
	return [hours * 1, minutes * 1]  
}

export function parseStringify(val){
	return JSON.parse(JSON.stringify(val))
}
					
export function setKeyObj(arr, res) {
	for (let item of arr) {
		let {
			key,
			parent_key,
			isMoney,
			ancestor
		} = item
		if (parent_key) {
			let The_parent = res[parent_key]
			if (The_parent) {
				let The_ancestor = The_parent[ancestor]
				if (The_ancestor) {
					item.content = The_ancestor[key] ? The_ancestor[key] : ''
				} else {
					item.content = The_parent[key] ? The_parent[key] : ''
				}
			}
		} else if (isMoney) {
			item.content = '￥' + res[key]
		} else {
			item.content = res[key] ? res[key] : ''
		}
	}
	return arr
}					

export function testPhone(phone){
	return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(phone)
}

export function isEmptyObject(obj) {
  return Object.keys(obj).length != 0;
}


// 时间戳转换时间
export function timestampToTime(timestamp, flag) {
	if (timestamp) {
		let newVla = (timestamp + '').length > 10 ? timestamp : timestamp * 1000;
		var date = new Date(newVla); //时间戳为10位需*1000，时间戳为13位的话不需乘1000

		var year = date.getFullYear();
		var month = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
		let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()

		let hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
		let minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
		let second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
		let time = ''
		if (flag) {
			time = `${year}-${month}-${day} ${hour}:${minute}:${second}`
		}
		else {
			time = `${year}-${month}-${day}`
		}
		return time
	}
	else {
		return ''
	}
	//注意：如果是Unix时间戳记得乘以1000。比如：PHP函数time()获得的时间戳就要乘以1000。			
}
